Skip to content

Comments

Enable bean validation#25

Merged
goekay merged 6 commits intomainfrom
enable-bean-validation
Jan 28, 2026
Merged

Enable bean validation#25
goekay merged 6 commits intomainfrom
enable-bean-validation

Conversation

@goekay
Copy link
Member

@goekay goekay commented Jan 28, 2026

Motivation: We want to validate incoming/outgoing OCPP messages. The SOAP world with CXF already understands XML-specific annotations and does validation. But JSON/Websocket world is missing them -> Use Jakarta validation APIs for this

  • Problem 1: POJOs generated by jsonschema2pojo-maven-plugin have these annotations (i.e. OCPP 1.6J security, and OCPP 2.0.1), but earlier versions (e.g. OCPP 1.2, 1.5, 1.6) dont have them.
  • Problem 2: Jackson does not apply validation out-of-the-box.

Solution to Problem 1: https://github.com/fillumina/krasa-jaxb-tools

exemplary class before:

@ToString
public class StartTransactionRequest implements RequestType {

    protected int connectorId;
    
    @XmlElement(required = true)
    protected String idTag;
    
    @XmlElement(required = true, type = String.class)
    @XmlJavaTypeAdapter(JodaDateTimeConverter.class)
    @XmlSchemaType(name = "dateTime")
    protected DateTime timestamp;
   
    protected int meterStart;
   
    protected Integer reservationId;

    // Getters and Setters
}

afterwards:

@ToString
public class StartTransactionRequest implements RequestType {

    @jakarta.validation.constraints.NotNull
    protected java.lang.Integer connectorId;
    
    @XmlElement(required = true)
    @jakarta.validation.constraints.NotNull
    @Size(max = 20)
    protected String idTag;
    
    @XmlElement(required = true, type = String.class)
    @XmlJavaTypeAdapter(JodaDateTimeConverter.class)
    @XmlSchemaType(name = "dateTime")
    @jakarta.validation.constraints.NotNull
    protected DateTime timestamp;
    
    @jakarta.validation.constraints.NotNull
    protected java.lang.Integer meterStart;
    
    protected java.lang.Integer reservationId;

    // Getters and Setters
}

Solution to Problem 2: https://www.baeldung.com/java-object-validation-deserialization

@goekay goekay merged commit 0519e3b into main Jan 28, 2026
1 check passed
@goekay goekay deleted the enable-bean-validation branch January 28, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant